package com.digua.base.socket.dispatcher

import com.digua.base.socket.response.ErrorResponse
import org.java_websocket.framing.Framedata

import java.nio.ByteBuffer


interface IResponseDispatcher {
    /**
     * 链接成功
     */
    fun onConnected(delivery: ResponseDelivery?)

    /**
     * 链接失败
     *
     * @param cause 失败原因
     */
    fun onConnectFailed(cause: Throwable?, delivery: ResponseDelivery?)

    /**
     * 链接断开
     */
    fun onDisconnect(delivery: ResponseDelivery?)

    /**
     * 接收到文本消息
     *
     * @param message  接收到的消息
     * @param delivery 消息发射器
     */
    fun onMessage(message: String, delivery: ResponseDelivery?)

    /**
     * 接收到二进制消息
     *
     * @param byteBuffer 接收到的消息
     * @param delivery   消息发射器
     */
    fun onMessage(byteBuffer: ByteBuffer, delivery: ResponseDelivery?)

    /**
     * 接收到 ping
     *
     * @param framedata 数据帧
     */
    fun onPing(framedata: Framedata?, delivery: ResponseDelivery?)

    /**
     * 接收到 pong
     *
     * @param framedata 数据帧
     */
    fun onPong(framedata: Framedata?, delivery: ResponseDelivery?)

    /**
     * 消息发送失败或接受到错误消息等等
     */
    fun onSendDataError(error: ErrorResponse?, delivery: ResponseDelivery?)
}